<style>
    .layui-form-label {
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
    }
    [lay-filter="storageInventoryInoutForm"] .layui-table-cell{
        padding: 0 5px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">盘验时间：</label>
                                    <div class="layui-input-inline">
                                        <input name="createTime" id="pTime" class="layui-input" type="text"
                                               placeholder="选择时间" autocomplete="off" style="width: 200px" readonly/>
                                    </div>
                                    <input name="startTime" id="startTime" type="hidden"/>
                                    <input name="endTime" id="endTime" type="hidden"/>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">盘验编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="resultCode" class="layui-input" type="text" placeholder="请输入盘验编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">盘验明细编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="resultDetailCode" class="layui-input" type="text" placeholder="请输入盘验明细编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">柜子编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="cabCode" class="layui-input" type="text" placeholder="请输入柜子编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="checkResultDetailBtnExport" class="layui-btn icon-btn color-green">导出盘验明细</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <!--<table class="layui-table" id="storageInventoryInoutDetailTable" lay-filter="storageInventoryInoutDetailTable"></table>-->
            <table class="layui-table" id="storageInventoryInoutDetailTable" lay-filter="storageInventoryInoutDetailTable"></table>
        </div>
    </div>
</div>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#storageInventoryInoutDetailTable',
            url: config.base + 'enterprisecab/cabinet/admin/checkedResultLabel/list',
            where:{sort:"id",order:"desc"},
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            limit: 5,
            limits:[5,10,20,30,40,50,60,70,80],
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', sort: true,width: 60}
                ,{field: 'detailCode', sort: true, title: '盘验明细编号',width: 165}
                ,{field: 'labelCode', sort: true, title: '刀具唯一码',width: 130}
                ,{field: 'cabCode', sort: true, title: '柜子编号'}
                ,{field: 'cabName', sort: true, title: '柜子名称'}
                , {field: 'spaceCode', title: '所属货位'}
                , {
                    field: 'skuPic', title: '图片', templet: function (d) {
                        if (d.skuPic) {
                            return '<img src="'+ d.skuPic + '" style="height: 20px;"/>';
                        }
                        return '';
                    }
                }
                , {field: 'skuCode', sort: true, title: '物料编号'}
                , {field: 'skuName', sort: true, title: '物料名称'}
                , {field: 'skuSpecOld', sort: true, title: '规格码'}
                , {field: 'productBrandName', sort: true, title: '品牌'}
                , {field: 'quantity', sort: true, title: '数量',width: 70}
                , {field: 'inCreatorName', title: '归还人'}
                , {field: 'code', title: '盘验记录编号',width: 160}
                ,{field: 'businessType', sort: true, title: '盘验前状态', width: 130, templet:function (d) {
                        if(d.businessType=='temp'){
                            return '暂存';
                        }else if(d.businessType=='repair'){
                            return '报修'
                        }else if(d.businessType=='recycle'){
                            return '报废'
                        }
                    }}
                ,{field: 'businessTypeChecked', sort: true, title: '盘验后状态', width: 130, templet:function (d) {
                        if(d.businessTypeChecked=='temp'){
                            return '暂存';
                        }else if(d.businessTypeChecked=='repair'){
                            return '报修'
                        }else if(d.businessTypeChecked=='recycle'){
                            return '报废'
                        }
                    }}
                , {field: 'createTime', sort: true, title: '盘验时间', width: 160}
            ]],
        });

        // 工具条点击事件
        table.on('tool(storageInventoryInoutDetailTable)', function (obj) {
            var data = obj.data;
            if(obj.event=='detail'){

            }

        });

        //监听排序
        table.on('sort(storageInventoryInoutDetailTable)', function(obj){
            table.reload('storageInventoryInoutDetailTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for(let key in field){
                field[key] = ''
            }
            insTb.reload({where: field,page: {curr: 1}},'data');
        });

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if(value){
                    let dateValue = value.split(" - ");
                    $("#startTime").val(dateValue[0]+" 00:00:00");
                    $("#endTime").val(dateValue[1]+" 23:59:59");
                }else {
                    $("#startTime").val("");
                    $("#endTime").val("");
                }
            }
        });

        //导出盘验明细
        $('#checkResultDetailBtnExport').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();

            if (sTime == "" && eTime == ""){
                layer.msg('请先选择时间！')
            } else {

                location.href = config.base + 'enterprisecab/cabinet/admin/checkedRepairResult/exportDetail?startCreateTime='+sTime+'&endCreateTime='+eTime;
            }
        });

    });
</script>